package com.education.welco.controller.app;

import com.education.common.pojo.AjaxResult;
import com.education.welco.feign.userFeign;
import com.education.welco.service.ISReportService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@Api(tags = {"APP-资源--评论举报"})
@RestController
@RequestMapping("/app/Report")
public class AppReportController {

    @Autowired
    private ISReportService reportService;
    @Autowired
    private userFeign userFeign;

    /**
     * @param repId 举报对象id
     * @param userId 举报人id
     * @param type   举报资源类型
     * @param text   举报文本
     * @return
     */
    @GetMapping("/commentReport")
    @ApiOperation(value = "评论举报", httpMethod = "GET")
    public AjaxResult commentReport(@RequestParam(value = "repId", required = true) String repId,
                                    @RequestParam(value = "content", required = false) String content,
                                    @RequestParam(value = "userId", required = true) String userId,
                                    @RequestParam(value = "type", required = true) String type,
                                    @RequestParam(value = "text", required = true) String text) {

        //根据userId搜索user
        Map<String, Object> byUserId = userFeign.findByUserId(Integer.valueOf(userId));
        //type = "4";//达人视频评论4

        Map<String, Object> map = new HashMap<>();
        map.put("userID", userId);
        map.put("userName", byUserId.get("name").toString());
        map.put("userIco", byUserId.get("image").toString());
        map.put("cKeyId", repId);
        //map.put("cKeyContent", content);
        map.put("cReportType", type);
        map.put("cReportRsn", text);
        reportService.insertSysForumsReport(map);
        return AjaxResult.success("操作成功");
    }
}
